package com.jd.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jd.entity.BannerEntity;
import com.jd.entity.ShareEntity;
import com.jd.service.BannerSrevice;
import com.jd.util.IdUtil;
/**
 * @author masicheng 
 * 时间 : 2020年12月16日 上午10:28:49 
 * 注释 :轮播图
 */
@Controller
@RequestMapping("/bannerController")
public class BannerController {

	@Autowired
	private BannerSrevice bannerSrevice;
	
	@RequestMapping("/banner")
	@ResponseBody
	public ArrayList<BannerEntity> banner(HttpServletRequest request){
		ArrayList<BannerEntity> bannerList = bannerSrevice.banner();
		return bannerList;
	}
	@RequestMapping("/getBannerById")
	@ResponseBody
	public BannerEntity getBannerById(HttpServletRequest request){
		String id = request.getParameter("id");
		BannerEntity banner = bannerSrevice.getBannerById(id);
		return banner;
	}
	@RequestMapping("/getShare")
	@ResponseBody
	public ShareEntity getShare(HttpServletRequest request){
		String userId = request.getSession().getAttribute("userId").toString();
		ShareEntity shareEntity = bannerSrevice.getShare(userId);
		return shareEntity;
	}
	@RequestMapping("/saveShare")
	@ResponseBody
	public Boolean saveShare(HttpServletRequest request){
		String userId = request.getSession().getAttribute("userId").toString();
		String num = request.getParameter("num");
		ShareEntity shareEntity = new ShareEntity();
		shareEntity.setId(IdUtil.getIdByUUId());
		shareEntity.setUserId(userId);
		shareEntity.setNum(num);
		shareEntity.setShareTime(new Date());
		Boolean i = bannerSrevice.saveShare(shareEntity);
		return i;
	}
	@RequestMapping("/out")
	public void out(HttpServletRequest request,HttpServletResponse response){
		HttpSession session = request.getSession();
		session.setAttribute("userId",null);
		try {
			response.sendRedirect("http://www.bfwcg.com/game/wechat/authorize?returnUrl=asdasdasd");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
